import { Actions } from "@/redux/actions.ts";
import { AppDispatch, RootState } from "@/redux/store.ts";
import { NavigateFunction } from "react-router";


export const navThunk = (n: NavigateFunction, path: string) => {
    n(path);
    return (dispatch: AppDispatch) => {
        dispatch(Actions.PUB.pushRoute(path));
    }
}

export const backThunk = (n: NavigateFunction) => {
    return (dispatch: AppDispatch, getState: () => RootState) => {
        n(getState().pub.routes[getState().pub.routes.length - 2] || '/');
        dispatch(Actions.PUB.popRoute());
    }
}